import Vue from 'vue'
import Vuex from 'vuex'
import { getItem, setItem } from '@/utils/storage.js'
Vue.use(Vuex)

const TOKEN_KEY = 'toutiao_token'

export default new Vuex.Store({
  state: {
    // 默认为空
    user: getItem(TOKEN_KEY) || null
  },
  mutations: {
    setUser(state, payload) {
      // 在login界面将登陆成功的token传过来,即payload参数
      state.user = payload
      setItem(TOKEN_KEY, payload)
    }
  },
  actions: {
  },
  modules: {
  }
})
